package com.qingke.design_pattern;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
//import java.util.HashMap;
//import java.util.Map;
//import java.util.Map.Entry;
import java.util.Properties;

public class PropertyManager {
	private static PropertyManager instance=null;
	private Properties properties=null;
//	private Map<String,String> properties=new HashMap<>();
	
	{
		properties=new Properties();
//		Properties p=new Properties();
		try {
			properties.load(new FileReader("designPattern.properties"));
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
//		for(Entry<Object,Object> e:.entrySet()){
//			Object key=e.getKey();
//			Object value=e.getValue();
//			if(key instanceof String && value instanceof String)
//				properties.put((String)e.getKey(),(String)e.getValue());
//		}
		
	}
	
	
	private PropertyManager(){
		
	}
	
	public static synchronized PropertyManager getInstance(){
		if(instance==null){
			instance=new PropertyManager();
		}
		return instance;
	}
	
	
	public String getProperty(String key){
		if(properties.getProperty(key)==null){
			properties.put(key,new String(""));
		}
		
		return properties.getProperty(key);
	}
	
	public String[] getPropertyList(String key){
		if(properties.getProperty(key)==null){
			properties.put(key,new String(""));
		}
		
		return properties.getProperty(key).split(",");
	}
}
